/**
 * 订单相关的服务接口
 */

import type {PageResultType} from "@/types/global";
import type {OrderBriefInfoType, OrderFormType, OrderPayInfoType, OrderQueryType, OrderStatType} from "@/types/order";
import {request} from "@/utils/http";
import type {BillCls} from "@/pagesOrder/types/ordercls";

/**
 * 获取订单统计数据
 */
export const getOrderStat = () => {
    return request<OrderStatType>({
        url: "/order/stat",
        method: "GET"
    })
}
/**
 * 分页获取订单列表
 * @param query
 */
export const getOrderList = (query: OrderQueryType) => {
    return request<PageResultType<OrderBriefInfoType>>({
        url: "/order/page",
        method: "POST",
        data: query
    })
}
/**
 * 分页获取订单列表
 * @param query
 */
export const queryOrdersWithPagination = (query: OrderQueryType) => {
    return request<PageResultType<OrderBriefInfoType>>({
        url: "/order/search",
        method: "POST",
        data: query
    })
}
/**
 * 根据提交的订单的商品计算订单金额
 * @param form
 */
export const calculateBillAmount = (form: OrderFormType) => {
    return request<BillCls>({
        url: "/order/calc-bill-amount",
        method: "POST",
        data: form
    })
}
/**
 * 创建订单
 * 返回订单号
 * @param form
 */
export const createOrder = (form: OrderFormType) => {
    return request<string>({
        url: "/order",
        method: "POST",
        data: form
    })
}
/**
 * 获取订单的支付信息
 * @param number
 */
export const getOrderPayInfo = (number: string) => {
    return request<OrderPayInfoType>({
        url: "/order/get-pay?number="+number,
        method: "GET",
    })
}
/**
 * 支付订单
 * @param number
 */
export const payOrder = (number: string) => {
    return request<string>({
        url: "/order/pay?number="+number,
        method: "GET",
    })
}
/**
 * 确认收货
 * @param number
 */
export const confirmReceived = (number: string) => {
    return request<string>({
        url: "/order/confirm?number="+number,
        method: "GET",
    })
}